package com.sa07.db.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.h2.Driver;

import com.sa07.db.DbConfig;
import com.sa07.db.DefaultSession;

/**
 * H2数据库数据库会话对象
 * 
 * @author Long.shangbo
 * 
 *         2014-2-15 下午6:52:11
 */
public class H2Session extends DefaultSession {

	private DbConfig dbConfig = null;

	private static String URL = null;

	public H2Session() {
	};

	public H2Session(DbConfig dbConfig) {
		this.dbConfig = dbConfig;
	}

	@Override
	protected Connection createConnection() throws SQLException {
		if (URL == null) {
			URL = "jdbc:h2:" + dbConfig.getDbName();
		}
		DriverManager.registerDriver(new Driver());
		Connection conn = DriverManager.getConnection(URL, dbConfig.getDbUserName(), dbConfig.getDbUserPwd());
		conn.setAutoCommit(false);
		return conn;
	}
}
